using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Data;
using System.Windows;
using System.Globalization;

namespace MyPublisher.Windows.Controls.Primitives
{
    [ValueConversion(typeof(object), typeof(int?))]
    public class Object2IntObject : IValueConverter
    {
        public static Object2IntObject Instance
        {
            get { return InstanceOf<Object2IntObject>.GetInstance(); }
        }

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == DBNull.Value || value == null)
                return null;
            else
                return System.Convert.ToInt32(value);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return DBNull.Value;
            else
                return System.Convert.ToInt32(value.ToString());
        }

        #endregion
    }
}
